package cn.ekuma.data.ui.swing.dnd;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.util.List;

import cn.ekuma.data.dao.bean.I_ViewBean;

public class BeanListTransferable implements Transferable {
	List<I_ViewBean> src;
	
	public BeanListTransferable(List<I_ViewBean> src) {
		this.src = src;
	}

	//====== The following methods implement the Transferable interface =====

	  // This is the custom DataFlavor for Scribble objects
	  public static DataFlavor beanListDataFlavor = new DataFlavor(
			  BeanTransferable.class, "baseBean");

	  // This is a list of the flavors we know how to work with
	  public static DataFlavor[] supportedFlavors = { beanListDataFlavor };

	  /** Return the data formats or "flavors" we know how to transfer */
	  public DataFlavor[] getTransferDataFlavors() {
	    return (DataFlavor[]) supportedFlavors.clone();
	  }

	  /** Check whether we support a given flavor */
	  public boolean isDataFlavorSupported(DataFlavor flavor) {
	    return (flavor.equals(beanListDataFlavor));
	  }

	  /**
	   * Return the scribble data in the requested format, or throw an exception
	   * if we don't support the requested format
	   */
	  public Object getTransferData(DataFlavor flavor)
	      throws UnsupportedFlavorException {
	    if (flavor.equals(beanListDataFlavor)) {
	      return src;
	    } else
	      throw new UnsupportedFlavorException(flavor);
	  }

}
